#include "IO.h"
#include "global.h"
#include "read.h"

void Jump(DiskPoint &point,int x)
{
	if(Round !=2) printf("j %d",x);point.pos=x;
	point.pretoken=80;
}
void Pass(DiskPoint &point,int &usedtok)
{
	if(Round !=2) putchar('p');inc(point.pos);
	usedtok++;
	point.pretoken=80;
}
bool Read(int d,DiskPoint &point,int &usedtok)
{
	int thistok=max((int)ceil(point.pretoken*0.8),16);
	if(thistok+usedtok>G) return false;

	if(Round !=2) putchar('r');
	usedtok+=thistok;
	point.pretoken=thistok;

    if(disk[d][point.pos])
    {
        int num= unit_num[d][point.pos],object_id=disk[d][point.pos];
		
		lstvis[object_id][num]=max(lstvis[object_id][num],timestamp);
		for(int r=object[object_id].last_request_point;r&&!request[r].is_done[num];r=request[r].prev_id)
        {
			request[r].remain--;
			request[r].is_done[num] = true;
			if(request[r].is_completed()&&!request[r].isbusy) donelist.push(r);
        }
    }
	inc(point.pos);
	return true;
}
queue<int> donelist;
void DoneReport()
{
    if(Round !=2) putint((int)donelist.size());
    while(!donelist.empty())
	{
		if(Round !=2) putint(donelist.front());
		donelist.pop();
	}
}
queue<int> busylist,Busy_intime[MAX_TIME_SLICING];
void BusyReport()
{
	static int r = 1;
	if(timestamp==1) r=1;
	static double waste=0,whole=0;
	for(;timestamp-request[r].burntime==105;r++) bebusy(r);
	if(Round !=2) putint((int)busylist.size());
	while(!busylist.empty())
	{
		if(Round !=2) putint(busylist.front());
		else if(timestamp>105) Busy_intime[timestamp-105].push(busylist.front());
		busylist.pop();
	}
		
}